#modeltag({tagcode:"jxbrms_systempost",term:"post_id=?",id:params[0]})
#include("/common/layout/bootstrap_form_layout.html")
#@layout()

#define title()
#(jxrb.message(actionName,"systemPost"))
#end
#define head()

#include("/common/layout/ztree_check_layout.html",treeDataUrl=jxwebpath.item+"post/groupTreeData/",treeLoadOkFunction="setOldPostid();")
<script>
  seajs.use(["jquery", "jx_msgbox", "jx_pinyin", "action_tree", "jac", "jx_check"], function ($, msgbox, jxpy, at) {

    $("#b_submit").on("click", function ()
    {
      if (!jxCheck.check()) {
        return false;
      }
      $("#group_id").val(getCheckedNodes());
      msgbox.confirm({url: "#(controllerKey)#(action)/"},
      function ()
      {
        msgbox.close();
        if (msgbox.messageType != 2)
          clearForm();
        window.parent.refreshTree($("#parentId").val());
      }, function ()
      {
        window.parent.refreshTree($("#parentId").val());
        if (msgbox.messageType != 2)
          returnInfo();
      });
    })
    var action = '#(action)';
    $("#b_return").on("click", function () {
      if(action == 'added'){
        location.href = "#(backurl)";
      }else{
        returnInfo()
      }
    });
    
    function returnInfo()
    {
      var parentId = $("#parentId").val();
      if(parentId == ""){
        location.href = "#(controllerKey)1-1"
      }else{
        location.href = "#(controllerKey)2-" + parentId;
      }
    }

    function clearForm()
    {
      if (action == 'added') {
        $("#viewNum").val(parseInt($("#viewNum").val()) + 1);
        $("#postName").val("");
        $("#postCode").val("");
      }
    }

    $(function ()
    {
      jxpy({nameObject: "#postName", codeObject: "#postCode"});
      if (action == "added") {
        at.setViewNum('#(systempost.post_id ??)');
      }

    });

    function changePost()
    {
      at.setViewNum($("#parentId").val());
    }

    $("#parentName").blur(function () {
      if ($("#parentName").val() == "") {
        $("#parentId").val("");
      }
    });

    function setOldPostid()
    {
      $("#old_group_id").val(getCheckedNodes());
    }

    window.changePost = changePost;
  });
</script>
#end

#define bodyExt()
class="gray-bg"
#end

#define form()
#include("info.html")
#end

#define formAfter()
<center>
  #jx_button({value:"action.save",class:"btn btn-primary"})&nbsp;&nbsp;&nbsp;&nbsp;
  #jx_button({value:"action.return",id:"b_return",class:"btn btn-danger"})
</center>
#end